package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.common.Result;
import org.example.entity.Payment;
import org.example.service.PaymentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {
    @Resource
    private PaymentService paymentService;

    /**
     * 路径传参不用加@RequestBody
     * @param payment
     * @return
     */
    @PostMapping
    public Result create(/*@RequestBody*/ Payment payment) {
        int result = paymentService.create(payment);
        log.info("新增结果：{}", result);
        if (result > 0) return Result.success(result);
        return Result.error("新增失败");
    }

    @GetMapping("/{id}")
    public Result<Payment> getById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getById(id);
        log.info("查询结果：{}", payment);
        if (payment != null) return Result.success(payment);
        return Result.error("数据不存在");
    }

//    /**
//     * 查询全部
//     *
//     * @param id
//     * @return
//     */
//    @GetMapping
//    public Result<Payment> getByAll() {
//        Payment payment = paymentService.getById(id);
//        log.info("查询结果：{}", payment);
//        if (payment != null) return Result.success(payment);
//        return Result.error("数据不存在");
//    }
}
